/*
 * Copyright (c) 2002-2006 by OpenSymphony
 * All rights reserved.
 */
package org.fordprefect.struts2jscalendarplugin.components;

import com.opensymphony.xwork2.util.ValueStack;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.UIBean;

/**
 * <!-- START SNIPPET: javadoc -->
 * 
 * Renders parts of the HEAD section for an HTML file. This is useful as some
 * themes require certain CSS and JavaScript includes.<p/>
 * 
 * If, for example, your page has ajax components integrated, without having the
 * default theme set to ajax, you might want to use the head tag with
 * <b>theme="ajax"</b> so that the typical ajax header setup will be included
 * in the page.<p/>
 * 
 * The tag also includes the option to set a custom datepicker theme if needed.
 * See calendarcss parameter for description for details.<p/>
 * 
 * If you use the ajax theme you can turn a debug flag on by setting the debug
 * parameter to <tt>true</tt>.
 * 
 * <!-- END SNIPPET: javadoc -->
 * 
 * <p/> <b>Examples</b>
 * 
 * <pre>
 * &lt;!-- START SNIPPET: example1 --&gt;
 * &lt;head&gt;
 *   &lt;title&gt;My page&lt;/title&gt;
 *   &lt;ww:head/&gt;
 * &lt;/head&gt;
 * &lt;!-- END SNIPPET: example1 --&gt;
 * </pre>
 * 
 * <pre>
 * &lt;!-- START SNIPPET: example2 --&gt;
 * &lt;head&gt;
 *   &lt;title&gt;My page&lt;/title&gt;
 *   &lt;ww:head theme=&quot;ajax&quot; calendarcss=&quot;calendar-green&quot;/&gt;
 * &lt;/head&gt;
 * &lt;!-- END SNIPPET: example2 --&gt;
 * </pre>
 * 
 * <pre>
 * &lt;!-- START SNIPPET: example3 --&gt;
 * &lt;head&gt;
 *   &lt;title&gt;My page&lt;/title&gt;
 *   &lt;ww:head theme=&quot;ajax&quot; debug=&quot;true&quot;/&gt;
 * &lt;/head&gt;
 * &lt;!-- END SNIPPET: example3 --&gt;
 * </pre>
 * 
 * @author Patrick Lightbody
 * @author Rainer Hermanns
 * @author Rene Gielen
 * @ww.tag name="head" tld-body-content="empty"
 *         tld-tag-class="com.opensymphony.webwork.views.jsp.ui.HeadTag"
 *         description="Render a chunk of HEAD for your HTML file"
 * @since 2.2
 */
public class Head extends UIBean {
	public static final String TEMPLATE = "jscalendar_head";

	private String calendarcss = "calendar-blue.css";
	private boolean debug;

	// add by marshal
	private String language;

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public Head(ValueStack stack, HttpServletRequest request,
			HttpServletResponse response) {
		super(stack, request, response);
	}

	protected String getDefaultTemplate() {
		return TEMPLATE;
	}

	public void evaluateParams() {
		super.evaluateParams();

		if (calendarcss != null) {
			String css = findString(calendarcss);
			if (css != null && css.trim().length() > 0) {
				if (css.lastIndexOf(".css") < 0) {
					addParameter("calendarcss", css + ".css");
				} else {
					addParameter("calendarcss", css);
				}
			}
		}

		addParameter("encoding", "UTF-8");
		addParameter("debug", Boolean.valueOf(debug).toString());

		// add by marshal
		if (this.language != null && this.language.trim().length() > 0) {
			this.addParameter("language", this.language);
		}
	}

	public String getCalendarcss() {
		return calendarcss;
	}

	/**
	 * The jscalendar css theme to use" default="calendar-blue.css
	 * 
	 * @ww.tagattribute required="false"
	 */
	public void setCalendarcss(String calendarcss) {
		this.calendarcss = calendarcss;
	}

	public boolean isDebug() {
		return debug;
	}

	/**
	 * Set to true to enable debugging mode for AJAX themes
	 * 
	 * @ww.tagattribute required="false"
	 */
	public void setDebug(boolean debug) {
		this.debug = debug;
	}

}
